<?php
error_reporting(E_ALL);
ini_set("display_errors", true);

$debug = true;
include_once 'appinclude.php';

$curr = "search";
include 'tabs.php'; ?>
<style> 
.dialog{ width:300px; border: blue 1px solid; margin: 12px 12px 12px 12px; }
.dTitle{ background-color: blue; color:white; font-weight: bold; padding: 2px 2px 2px 2px; }
.dBody { padding: 5px 5px 5px 5px; }
.superLabel { margin-top: 6px; margin: 2px;}
.myInput { width: 200px; }
select { width: 100px; }
.mySelect { width: 200px; }
</style>
<!-- link rel="stylesheet" type="text/css" href="<?=APP_CALLBACK_URL?>typeahead.css?v=6" / -->
<style><? include_once 'typeahead.css' ?></style>
<script type="text/javascript" src="<?=APP_CALLBACK_URL?>typeahead.js?v=2"></script>
<div class="dialog">
	<div class="dTitle">Where would you like a ride to?</div>
	<div class="dBody">
		<form>
			<div class="superLabel">Where would you like to go?</div>
			<div class="zipContainer" >
				<input name="zip" id="zip" autocomplete="off" type="text" maxlength="20" class="myInput" />
			</div>
			<div class="superLabel">When would you like to travel? </div>
			<fb:editor-date label="" value="1199142000" />
			<div class="superLabel">How flexible are you? </div>
			<select name="flex" class="mySelect">
				<option value="day">It must be that day</option>
				<option value="week">Give or take a week is fine</option>
				<option value="month">Give or take a month is fine</option>
				<option value="year" selected="selected">Any time  will do</option>
			</select>
			<div align="right">
				<input type="submit" value="Search" />			
			</div>
		</form>
	</div>
</div>
<script>
</script>
<? 
//print_debug($_REQUEST);
if(isset($_REQUEST['zip']))
{
	$strDate = isset($_REQUEST['date_month']) ? $_REQUEST['date_month'] . "/" . $_REQUEST['date_day'] : null;
	$rides = listRides($_REQUEST['zip'], null, $strDate, isset($_REQUEST['flex']) ? $_REQUEST['flex'] : null);
	?>
	<div class="listTable">
		<? while($ride = mysql_fetch_assoc($rides) ){ ?>
		<div class="listRow">
			<fb:profile-pic uid="<?=$ride['uid']?>" size="square"  style="float:left" />
				<div class="itemTitle">
					<fb:name uid="<?=$ride['uid']?>" useyou="false" /> is going there
					on <?=date("D, d M Y", strtotime($ride['departure_time']))?>
					at <?=date("h:ia", strtotime($ride['departure_time']))?>
				</div>
				<div class="itemDesc">
					<?=$ride['description']?>
				</div>
				<div><fb:pronoun uid="<?=$ride['uid']?>" /> has room for <?=$ride['seats_available']?> more people.</div>
				<br clear="all" />
		
		</div>
		<? } ?>
	</div>
<? } ?>
<script> 
options = {
		preMsgTxt: "Search for a ride",	// text to display when nothing has been typed
		menuOpacity: 94, 					// opacity of the menu
		ajaxUrl: "http://www2.newpaltz.edu/~plotkin2/bumaride/locationService.php",	// url to your data source, must be absolute URL
		focus: false,						// whether or not to auto-focus the textbox upon creation
		onEnter: function(event) {},
		delayTime: 100,						// amount of idle time after a keypress before making the ajax call
		clearOnEnter: false					// whether or not to clear the text after they hit enter
	};

var suggestr = new ajaxSuggestFbml(document.getElementById('zip'),options);
</script>
